package cn.jcet.mapreduce.outputformat;

import cn.jcet.mapreduce.bean.FlowBean;
import cn.jcet.mapreduce.flowsum.FlowCountDriver;
import cn.jcet.mapreduce.flowsum.FlowCountMapper;
import cn.jcet.mapreduce.flowsum.FlowCountReduce;
import cn.jcet.mapreduce.flowsum.ProvincePartitioner;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

/**
 * @author 鲜磊
 * @Date 2020/12/15 11:41
 */
public class FilterDriver {

    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
        args = new String[]{"E:\\code\\inputlog","e:/code/outlog2"};

        Configuration conf = new Configuration();
        // 1、创建job对象
        Job job = Job.getInstance(conf);
        //2、设置jar的位置路径，反射获取
        job.setJarByClass(FilterDriver.class);
        //3、关联map和reduce的类
        job.setMapperClass(FilfterMapper.class);
        job.setReducerClass(FifterReduce.class);
        //4、设置map的的输出数据类型
        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(NullWritable.class);
        //5、设置最终的输出数据类型
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(NullWritable.class);

        // 是指自定义输出格式化设置
        job.setOutputFormatClass(FilterOutputFormat.class);
        //6、设置输入输出路径参数
        FileInputFormat.setInputPaths(job,new Path(args[0]));
        FileOutputFormat.setOutputPath(job,new Path(args[1]));
        //7、提交任务
        boolean result = job.waitForCompletion(true);
        System.exit(result? 0 : 1);
    }
}
